home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / xplatfrm / motxas / do4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-14  |  4.2 KB  |  195 lines

  1. /*
  2.  *      MC6804 specific processing
  3.  */
  4.  
  5. #define IMMED   0
  6. #define IND     1
  7. #define OTHER   2
  8.  
  9. /* special addresses */
  10. #define XREG    0x80
  11. #define YREG    0x81
  12. #define SD1REG  0x82
  13. #define SD2REG  0x83
  14. #define ACCUM   0xFF
  15.  
  16. /*
  17.  *      localinit --- machine specific initialization
  18.  */
  19. localinit()
  20. {
  21.     install("x",XREG);
  22.     install("X",XREG);
  23.     install("y",YREG);
  24.     install("Y",YREG);
  25.     install("a",ACCUM);
  26.     install("A",ACCUM);
  27. }
  28.  
  29. /*
  30.  *      do_op --- process mnemonic
  31.  */
  32. do_op(opcode,class)
  33. int opcode;    /* base opcode */
  34. int class;    /* mnemonic class */
  35. {
  36.     char *skip_white();
  37.     int     dist;   /* relative branch distance */
  38.     int     amode;  /* indicated addressing mode */
  39.     int     r1;     /* first eval() for mvi */
  40.  
  41.     if (( *Operand == '[' ) || ( *Operand == ','))
  42.         amode = IND;
  43.     else if( *Operand == '#' )
  44.         amode = IMMED;
  45.     else
  46.         amode = OTHER;
  47.  
  48.     switch(class){
  49.         case INH:                       /* inherent addressing */
  50.             emit(opcode);
  51.             return;
  52.         case APOST:             /* A address in mem follows opcode */
  53.             emit(opcode);
  54.             emit(ACCUM);
  55.             return;
  56.         case REL:                       /* short relative branches */
  57.             if( eval() )
  58.                 dist = Result - (Pc+1);
  59.             else dist = -1;
  60.             if( (dist >15 || dist <-16) && Pass==2){
  61.                 error("Branch out of Range");
  62.                 dist = -1;
  63.                 }
  64.             emit(opcode + (dist&0x1F));
  65.             return;
  66.         case BTB:
  67.         case SETCLR:
  68.             eval();
  69.             if(Result <0 || Result >7){
  70.                 error("Bit Number must be 0-7");
  71.                 return;
  72.                 }
  73.             emit( opcode + Result);
  74.             if(*Optr++ != ',')error("Missing comma");
  75.             Optr = skip_white(Optr);
  76.             eval();
  77.             emit(lobyte(Result));
  78.             if( class == SETCLR )
  79.                 return;
  80.             if(*Optr++ != ',')error("Missing comma");
  81.             Optr = skip_white(Optr);
  82.             if( eval() )
  83.                 dist = Result - (Old_pc+3);
  84.             else dist = -3;
  85.             if( (dist >127 || dist <-128) && Pass==2){
  86.                 error("Branch out of Range");
  87.                 dist = -3;
  88.                 }
  89.             emit(lobyte(dist));
  90.             return;
  91.         case EXT:               /* jsr, jmp */
  92.             eval();
  93.             emit(opcode | (hibyte(Result) & 0x0F));
  94.             emit(lobyte(Result));
  95.             return;
  96.         case BPM:       /* brset/clr 7,accum,target */
  97.             emit(opcode);
  98.             emit(ACCUM);
  99.             if( eval() )
  100.                 dist = Result - (Old_pc + 3);
  101.             else dist = -3;
  102.             if ((dist > 127 || dist < -128) && Pass == 2) {
  103.                 error("Branch out of range");
  104.                 dist = -3;
  105.                 }
  106.             emit(lobyte(dist));
  107.             return;
  108.         case MVI:
  109.             eval();
  110.             r1 = Result;    /* save result */
  111.             if (*Optr++ != ',')
  112.                 warn("Missing comma");
  113.             Optr = skip_white(Optr);
  114.             eval();
  115.             mvi(opcode,r1,Result);
  116.             return;
  117.         case CLRX:      /* mvi xreg,0 */
  118.             mvi(opcode,XREG,0);
  119.             return;
  120.         case CLRY:      /* mvi yreg,0 */
  121.             mvi(opcode,YREG,0);
  122.             return;
  123.         case LDX:       /* mvi xreg data */
  124.             if (amode == IMMED) Optr++;
  125.             eval();
  126.             mvi(opcode,XREG,Result);
  127.             return;
  128.         case LDY:       /* mvi yreg data */
  129.             if (amode == IMMED) Optr++;
  130.             eval();
  131.             mvi(opcode,YREG,Result);
  132.             return;
  133.         case NOIMM:
  134.             if( amode == IMMED ){
  135.                 error("Immediate Addressing Illegal");
  136.                 return;
  137.                 }
  138.         case GEN:
  139.             if ( amode == IMMED ) {
  140.                 Optr++;
  141.                 eval();
  142.                 emit(opcode | 0x08);
  143.                 emit(lobyte(Result));
  144.                 return;
  145.                 }
  146.             if( amode == IND ){
  147.                 Optr++;
  148.                 eval();
  149.                 if ((*Optr != ']') && (*Operand != ','))
  150.                     warn("Missing ']'");
  151.                 if (Result != XREG && Result != YREG) {
  152.                    error("Operand must be X or Y register");
  153.                    emit(opcode);
  154.                    return;
  155.                 }
  156.                 emit(opcode | ((Result&0x01)<<4));
  157.                 return;
  158.                 }
  159.             eval();
  160.             if (XREG <= Result && Result <=SD2REG){
  161.                 /*check for short direct cases*/
  162.                 if ( opcode==0xE6 ) {   /* inc */
  163.                     emit(0xA8 + (Result-XREG));
  164.                     return;
  165.                     }
  166.                 if ( opcode==0xE7 ) { /* dec */
  167.                     emit(0xB8 + (Result-XREG));
  168.                     return;
  169.                     }
  170.                 if ( opcode==0xE0 ) { /* lda */
  171.                     emit(0xAC | (Result-XREG));
  172.                     return;
  173.                     }
  174.                 if ( opcode==0xE1 ) { /* sta */
  175.                     emit(0xBC | (Result-XREG));
  176.                     return;
  177.                     }
  178.                 }
  179.             /* else direct addressing */
  180.             emit( opcode | 0x18);
  181.             emit(lobyte(Result));
  182.             return;
  183.         default:
  184.             fatal("Error in Mnemonic table");
  185.         }
  186. }
  187.  
  188. mvi(op,to,from)
  189. int op,to,from;
  190. {
  191.     emit(op);
  192.     emit(to);
  193.     emit(from);
  194. }
  195.